<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Project extends Admin_Controller
{
	private static $data = array();
	protected $models=['project_model','type_model','company_model'];
	public function __construct()
	{
		parent::__construct();	
		
	}
	
	//待审核
	public function issue0()
	{
	    $companyId=$this->input->get('companyId');
	    self::$data['companyId']=$companyId;
	    self::$data['dataurl']=site_url('admin/project/getIssue0');
	    $this->load->view('admin/project/list.html',self::$data);
	}
	//审核通过
	public function issue1()
	{
	    $companyId=$this->input->get('companyId');
	    self::$data['companyId']=$companyId;
	    self::$data['dataurl']=site_url('admin/project/getIssue1');
	    $this->load->view('admin/project/list.html',self::$data);
	}
	//审核被拒
	public function issue2()
	{
	    $companyId=$this->input->get('companyId');
	    self::$data['companyId']=$companyId;
	    self::$data['dataurl']=site_url('admin/project/getIssue2');
	    $this->load->view('admin/project/list.html',self::$data);
	}
	
	public function getIssue0(){
	    $this->getList(0);
	}
	public function getIssue1(){
	    $this->getList(1);
	}
	public function getIssue2(){
	    $this->getList(2);
	}
	
	//获取资讯列表数据
    public function getList($issue){
        $companyId=$this->input->get('companyId');
        $search=$this->input->get('search');
        $page=$this->input->get('page');
        $limit=$this->input->get('limit');
        $page=$page-1;
        $offset=$page*$limit;
        
        $where=['is_delete'=>0,'issue'=>$issue];
        if($companyId){
            $where['companyId']=$companyId;
        }
        $dbArray['like']=['project.title'=>$search];
        $count=$this->project_model->getWhere_num($where,$dbArray);
        $dbArray['page']=['limit'=>$limit,'offset'=>$offset];
        $project=$this->project_model->getWhere($where,'*',$dbArray);
        
        foreach ($project as $key=>$val){
            $project[$key]['serviceTypeIds']=explode('|', $val['serviceTypeIds']);
            $project[$key]['createTime']=format_time($val['createTime']);
        }
        
        if($project){
            show200_admin($project,$count);
        }else{
            show400_admin();
        }
    }
    
    //通过审核
    public function able(){
        $projectId=$this->input->post('projectId');
        $res=$this->project_model->updateWhere(['projectId'=>$projectId],['issue'=>1]);
        if($res){
            show200_admin([],'','操作成功');
        }else{
            show400_admin('操作失败');
        }
    }
    //拒绝通过审核
    public function disable(){
        $projectId=$this->input->post('projectId');
        $res=$this->project_model->updateWhere(['projectId'=>$projectId],['issue'=>2]);
        if($res){
            show200_admin([],'','操作成功');
        }else{
            show400_admin('操作失败');
        }
    }
    
    //添加资讯
    public function add(){
        $type=$this->type_model->getWhere(['flag'=>10]);
        $service=$this->type_model->getWhere(['flag'=>9]);
        
        self::$data['type']=$type;
        self::$data['service']=$service;
        $this->load->view('admin/project/add.html',self::$data);
    }
    //添加或更新文章
    public function action(){
        $data=$this->input->post();
        //var_dump($data);
        
        if(isset($data['serviceTypeIds'])){
            $data['serviceTypeIds']=implode('|', $data['serviceTypeIds']);
        }else{
            $data['serviceTypeIds']='';
        }
        if(isset($data['file'])){
            unset($data['file']);
        }
        if(isset($data['projectId'])&&!empty($data['projectId'])){
            //更新
            $res=$this->project_model->updateWhere(['projectId'=>$data['projectId']],$data);
        }else{
            //添加
            $res=$this->project_model->insert_time($data);
        }
        if($res){
            show200_admin([],'','操作成功');
        }else{
            show400_admin('操作失败');
        }
    }
    //删除
    public function del(){
        $projectIds=$this->input->post('projectIds');
        $res=$this->project_model->delWhere_in_logic('projectId',$projectIds);
        if($res){
            show200_admin([],'','操作成功');
        }else{
            show400_admin('操作失败');
        }
    }
   
	
	
	
	
	
	
	
	
}
/* End of file Login.php */